<!--tvm票款差异协查-->
<template>
  <div class="TvmTicketCYXC el-card is-always-shadow el-card__body">
    <avue-crud
      ref="TvmTicketCYXC"
      :option="option"
      :table-loading="listLoading"
      :data="data"
      :page.sync="page"
      :search.sync="searchForm"
      @search-change="handleFilter"
      @selection-change="selectionChange"
      @refresh-change="getList"
      @on-load="getList">
      <template slot="menuRight">
        <el-button type="primary"  size="mini" @click="exportData">导出</el-button>
      </template>
      <template slot-scope="scope" slot="lineCodeSearch">
        <el-select v-model="searchForm.lineCode" placeholder="请选择" style="width: 150px" clearable @change="changeLine" filterable>
          <el-option
            v-for="(item,index) in lineCodes"
            :key="index"
            :label="item.name"
            :value="item.code">
          </el-option>
        </el-select>
      </template>
      <template slot-scope="scope" slot="stationCodeSearch">
        <el-select v-model="searchForm.stationCode" placeholder="请选择" style="width: 150px" clearable @change="changeStation" filterable>
          <el-option
            v-for="(item,index) in stationCodes"
            :key="index"
            :label="item.name"
            :value="item.code">
          </el-option>
        </el-select>
      </template>
      <template slot-scope="scope" slot="tvmOrderSearch">
        <el-select v-model="searchForm.tvmOrder" placeholder="请选择" style="width: 150px" filterable>
          <el-option
            v-for="(item,index) in tvmCodes"
            :key="index"
            :label="item.tvmCode"
            :value="item.tvmCode">
          </el-option>
        </el-select>
      </template>
      <template slot="searchMenu" slot-scope="{row,size}">
        <el-button :size="size" @click="()=>{setSearchFiledsEmpty(row);setSearchFiledsEmpty(searchForm)}" icon="el-icon-delete">清空</el-button>
      </template>
      <template slot-scope="scope" slot="menu">
        <el-button type="text" size="small" plain @click.stop="previewEditor(scope.row,1)">预览</el-button>
<!--        <el-button v-if="scope.row.replyStatus=='0'" type="text" size="small" plain @click.stop="previewEditor(scope.row,2)">编辑</el-button>-->
      </template>
    </avue-crud>
    <HuikuiInfo ref="HuikuiInfo" v-if="isShowDia"></HuikuiInfo>
</div>
</template>


<script>
    import {getForm, postForm} from '@/api/gen/gen'
    import ExportJsonExcel from "js-export-excel";
    import HuikuiInfo from './JDZYDLCK/HuikuiInfo';
    import {
      getgetStationCodes,
      getLineCodes,
      getLineName,
      getQianxiangType,
      getRepalceStatus,
      getStationName,
      getXieChaStatusFormat,
      replayStatus,
      getStationByCode,
      xieChaStatus,
      setSearchFiledsEmpty,
      clearSelect,
      getMappingStatus,
      getMappingStatusArray,
      getLineAllAsyn,
      getSwPmTvmCodeList
    } from '../../../../../../api/subwayRat/commonCheck';
    import {exportDataToExcel} from "../../../../../../api/subwayRat/exportSelf";
    import transitUtil from "../../../../../../api/subwayRat/transitUtil";
    import {
      get_xw_SwAuTvmMoneyAssistListOther,
      submitData_xw_SwAuTvmMoneyAssist
    } from "../../../../../../api/stationTiecketManager/shuJuXieChaGuanLi/TVM/XT/TVMXTSJCY/JDZYDLCK";
    export default {
      components:{
        HuikuiInfo,
      getLineCodes
      },
      data() {
            return {
              lineCodes:[],
              stationCodes:[],
              tvmCodes:[],
              selectKeys:[], //存放对像
              selectKeyVals:[], //存放值
              tvmCodes:[],
              isShowDia:false,
              listLoading: true,
              searchForm:{
                lineCode:'',
                stationCode:'',
                tvmOrder:''
              },
              data: [],
              page: {
                total: 0, // 总页数
                currentPage: 1, // 当前页数
                pageSize: 20, // 每页显示多少条,
                isAsc: false// 是否倒序
              },
              option:{},
            }
        },
        created() {
          this.option=this.getOption();
        },
        methods: {
          setSearchFiledsEmpty,
          getList() {
            this.listLoading = true;
            Object.assign(this.searchForm,this.page);
            get_xw_SwAuTvmMoneyAssistListOther(this.searchForm).then((response)=>{
              this.data = response.data.data.list;
              this.listLoading = false;
              this.page.total=response.data.data.pageInfo.total;
              // this.data = response.data.data;
              // this.listLoading = false;
              // this.page.total=response.data.total;
            });
          },
          selectionChange(list){
            this.selectKeys=list;
            this.selectKeyVals=[];
            for(let i=0;i<list.length;i++){
              this.selectKeyVals.push(list[i].id);
            }
          },
          handleFilter(params, done) {
            Object.assign(this.searchForm,params);
            this.getList()
            done()
          },
          submitData(){
            if(this.selectKeys.length<=0){
              this.$message.warning("请选择提交的数据！");
              return;
            }

            for(let i=0;i<this.selectKeys.length;i++){
              if(this.selectKeys[i].replyStatus==1){
                this.$message.warning("请选择未回馈数据！");
                return;
              }
            }
            //下发
            submitData_xw_SwAuTvmMoneyAssist({ids:this.selectKeyVals.join(',')}).then(res=>{
              if(res.data.code==0){
                this.$message.success("操作成功！");
                this.getList();
              }else{
                this.$message.error("操作失败！");
              }
            })

          },
          changeLine(v){ //改变线路时
            let p={};
            p.line_code=v;
            getStationByCode(p).then(res=>{
              this.stationCodes=res.data;
              this.searchForm.stationCode='';
              this.searchForm.tvmOrder='';
            })
          },
          isassistInvestStatus(){ // 是否协查
            for(let i=0;i<this.selectKeys.length;i++){
              let row=this.selectKeys[i];
              if(row.assistInvestStatus==3){
                return false
              }
            }
            return true;
          },
          getLineName(query){
            let re="";
             getLine(query).then(async res=>{
               re=await res.data.name;
            });
            return re;
          },
          changeStation(v){ //改变车站
            let param={};
            param.lineCode=this.searchForm.lineCode;
            param.stationCode=v;
            getSwPmTvmCodeList(param).then(r=>{
              this.tvmCodes=r.data;
            });
          },
          previewEditor(row,type){ //回馈预览
            this.isShowDia=true;
            this.$nextTick(()=>{
              this.$refs.HuikuiInfo.recallShow(row.id,row,type);
            })
          },
          async exportData(){ // 导出
            this.searchForm.pageNo=1;
            this.searchForm.pageSize=1000000000;
            if(this.selectKeys.length>0){
                exportDataToExcel(this.selectKeys,this.option.column,'TVM票款差异协查');
            }else {
              let res=await get_xw_SwAuTvmMoneyAssistListOther(this.searchForm);
              let data = res.data.data;
              exportDataToExcel(data,this.option.column,'TVM票款差异协查');
            }
          },
          getOption(){
            let th=this;
            return  {
              emptyBtn:false,
              editBtn:false,
              delBtn:false,
              addBtn:false,
              border: true,
              index:true,
              indexLabel:'序号',
              align:'center',
              menuWidth:150,
              menuAlign:'center',
              selection: true,
              reserveSelection:false,
              column:[
                {prop:'lineCode',label:'线路',type:'select',search:true,searchslot:true,formatter: function(row, value , label, column){
                    return getLineName(value);
                  }},
                {prop:'stationCode',label:'车站',search:true,searchslot:true,formatter: function(row, value , label, column){
                    return getStationName(row.lineCode,value);
                  }},
                {prop:'tvmOrder',label:'TVM编号',search:true,searchslot:true},
                {prop:'boxCashType',label:'钱箱类型',formatter :function(row, value , label, column){
                    return getQianxiangType(value);
                  },},
                {prop:'cashBoxCode',label:'钱箱编号'},
                {prop:'sendTime',label:'通知时间',type:'date',search:true,valueFormat:'yyyy-MM-dd'},
                {prop:'replyReason',label:'归属机电专业回馈',search:true,type:'select',dicData: getMappingStatusArray('JD_REPLY_REASON'),
                  formatter:function(row, value , label, column){
                    return getMappingStatus('JD_REPLY_REASON',value);
                  }},
                {prop:'operatorName',label:'操作员'},
                {prop:'operatorCode',label:'操作员工号'},
                {prop:'jdReplyStatus',label:'回馈状态',type:'select',dicData:replayStatus(),search:true,
                  formatter:function(row, value , label, column){
                    return getMappingStatus('jd_reply_status',value);
                  }}
            ]
            }
          },
          otherVueAction(){ //供其他Vue页面调用
            let th=this;
            transitUtil.$on('PK_call',(param)=>{
              get_xw_SwAuTvmMoneyAssistListOther({relationid:param.id}).then((response)=>{
                th.data = response.data.data;
                th.previewEditor(th.data[0]);
              });
            })
            transitUtil.$on('PK_view',(param)=>{
              this.searchForm.relationid = param.id;
              this.getList();
            });

          }
          },
      mounted() {
        getLineAllAsyn().then(res=>{ //获取线路
          this.lineCodes=res.data;
        });
        this.otherVueAction();
      }
    }
</script>
<style lang="scss">

</style>
